function newEvent(categoryId, reminderId, repeatId, datetime, name, desc,year, month, day){
	 	
	var connection = new SQLite("db.sqlite");
		try{
			connection.execute("INSERT INTO tb_event (categoryId , reminderId, repeatId , datetime , name , description ,month, year, day) "+
							"VALUES("+categoryId+", "+reminderId+","+repeatId+","+datetime+",'"+name+"','"+
							desc+"',"+year+","+month+","+day+")");
		}catch(err){
			alert("Something it's bad. I think that you don't have the tables.");
			return;
		}		
}
function newCategory(categoryName){
	
	var connection=new SQLite("db.sqlite");
	try{
		connection.execute("INSERT INTO tb_category (categoryName) VALUES ('"+categoryName+"')");
	}catch(err){
		alert("Something it's bad. I think that you don't have the tables.");
		return;
	}
	
}
function getEventByDate(month, year, day){
	
	var connection = new SQLite("db.sqlite");
	try{
		var res = connection.execute("select * from tb_event where day="+day+
									 " and year="+year+" and month="+month);	
	}catch(err){
		alert("Something it's bad. I think that you don't have the tables.");
		return;
	}
	for (var i = 0; i<res.length; ++i){
		try{
		var cname = connection.execute("select categoryName from tb_category where categoryId="+res[i].categoryId);
		var remind = connection.execute("select remind from tb_reminder where reminderId="+res[i].reminderId);
		var rep = connection.execute("select repeat from tb_repeat where repeatId="+res[i].repeatId);
		}catch(err){
			alert("Something it's bad. I think that you don't have the tables.");
			return;
		}
		alert(cname[0].categoryName+"-"+remind[0].remind+"-"+"-"+res[i].year+"-"+res[i].month+"-"+res[i].day+"-"+res[i].datetime+"-"+
			  res[i].name+"-"+res[i].description+"-"+rep[0].repeat);
	}

}

function getEventByMonth(year, month){
	var connection = new SQLite("db.sqlite");
	try{
		var res = connection.execute("select * from tb_event where and year="+year+
									 " and month="+month);	
	}catch(err){
		alert("Something it's bad. I think that you don't have the tables.");
		return;
	}
	for (var i = 0; i<res.length; ++i){
		try{
		var cname = connection.execute("select categoryName from tb_category where categoryId="+res[i].categoryId);
		var remind = connection.execute("select remind from tb_reminder where reminderId="+res[i].reminderId);
		var rep = connection.execute("select repeat from tb_repeat where repeatId="+res[i].repeatId);
		}catch(err){
			alert("Something it's bad. I think that you don't have the tables.");
			return;
		}
		alert(cname[0].categoryName+"-"+remind[0].remind+"-"+"-"+res[i].year+"-"+res[i].month+"-"+res[i].day+"-"+res[i].datetime+"-"+
			  res[i].name+"-"+res[i].description+"-"+rep[0].repeat);
	}
}



function getCategory(){
	var conn = new SQLite("db.sqlite");
	try{
		var result = conn.execute("select categoryName from tb_category");
	}catch(err){
		alert("Something it's bad. I think that you don't have the tables.");
		return;
	}
	for (i = 0; i<result.length; ++i){
		alert(result[i].categoryName);
	}
}

function getRepeat(){
	var connection = new SQLite("db.sqlite");
	try{
	var res= connection.execute("select repeat from tb_repeat");
	}catch(err){
		alert("Something it's bad. I think that you don't have the tables.");
		return;
	}
	
	for (var i = 0; i<res.length; ++i){
		alert(res[i].repeat);
	}
}


function getReminder(){
	var connection = new SQLite("db.sqlite");
	try{
		var res = connection.execute("select remind from tb_reminder");
	}catch(err){
		alert("Something it's bad. I think that you don't have the tables.");
		return;
	}
	
	for (var i = 0; i<res.length; ++i){
		alert(res[i].remind);
	}
}
